package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.MethodLinesOfCodeVisitor;


public class MethodLinesOfCode extends Measure {
	private double value;

	public MethodLinesOfCode() {
		super();
		value = 0d;
		addApplicableGranularity(Granularity.METHOD);
	}

	@Override
	public String getName() {
		return "Method's Lines of Code";
	}

	@Override
	public String getAcronym() {
		return "MLoC";
	}

	@Override
	public String getDescription() {
		return "Return the number of lines of code of a method, excluding blank lines and comments";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return 0;
	}

	@Override
	public double getRefValue() {
		return 0;
	}

	@Override
	public <T> void measure(T unit) {

		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		MethodLinesOfCodeVisitor visitor = null;
		if (unit instanceof IMethod) {
			visitor = new MethodLinesOfCodeVisitor();
			parse.accept(visitor);
			IMethod method = (IMethod)unit;

			value = visitor.getNumberOfLinesOfCode(method);
		}
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value; 
	}
}
